/*****************************************************\
* Copyright (c) 2020 The game2d Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.

* Author:         dzlua - https://gitee.com/dzlua/game2d.git
* Email:          505544956@qq.com
* FileName:       ctrls/ui.cc
* Create Time:    2020/03/22 15:28:27
* Description:    /
\****************************************************/
#include "ui.h"

namespace g2d {
namespace ctrl {
  void UserInterface::set_root(Layout *layout) {
    if (root_) root_->decref();
    root_ = layout;
    if (root_) {
      root_->incref();
      int w, h;
      g2d_->window_size(&w, &h);
      root_->set_rect(0.f, 0.f, (float)w, (float)h);
    }
  }
  Layout* UserInterface::root() const { return root_; }
  void UserInterface::update(Input &inp, Audio &aud) {
    if (!enabled_) return;
    if (!root_) return;
    root_->update(inp, aud);
  }
  void UserInterface::render(Renderer &r) {
    if (!visible_) return;
    if (root_)
      root_->render(r);
  }
} // end namespace ctrl
} // end namespace g2d